package net.xuele.learn.mq;

import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.common.message.MessageExt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public class MessageProcessor {

    @Autowired
    private MessageProducer messageProducer;

    @Autowired
    private RocketMqProperty rocketMqProperty;

    public Boolean handleMessage(MessageExt messageExt) {
        String topic = messageExt.getTopic();
        String tag = messageExt.getTags();
        String body = new String(messageExt.getBody());
        String key = messageExt.getKeys();
        log.info("handleMessage key is {}, topic :{}, tag : {}, body: {}", key, topic, tag, body);

        //如果是不等消息
        if (Constant.CLAIM_TAG.equals(tag)) {
            ClaimRecord claimRecord = JSON.parseObject(body, ClaimRecord.class);
            log.info("收到的是补登消息={}",claimRecord.toString());
            return true;
        } else if (Constant.ACK_TAG.equals(tag)) {
            // 如果是补登确认消息
            ClaimAck claimAck = JSON.parseObject(body, ClaimAck.class);
            log.info("收到的是补登确认消息={}",claimAck.toString());
            return true;
        }

        return false;
    }
}
